package com.unionfetch.content_home.presenter

import com.unionfetch.content_home.bean.AccountCount
import com.unionfetch.content_home.bean.AccountLeverInfo
import com.unionfetch.content_home.bean.DemoAccountInfo
import com.unionfetch.content_home.bean.LiveAccountInfo
import com.unionfetch.content_home.bean.request.AddDemoAccountRequest
import com.unionfetch.content_home.bean.request.AddLiveAccountRequest
import com.unionfetch.content_home.bean.request.ModifyDemoLeverRequest
import com.unionfetch.content_home.bean.request.ModifyLeverRequest
import com.unionftech.common.common.bean.SystemUserInfo
import com.unionfetch.content_home.contract.AccountContract
import com.unionfetch.content_home.model.AccountModel
import com.unionftech.common.base.mvp.IBaseView
import com.unionftech.common.base.mvp.impl.BasePresenter
import com.unionftech.common.base.mvp.impl.IBaseCallBack
import com.unionftech.common.bean.ResponseResult

class AccountPresenter : BasePresenter<IBaseView, AccountModel>(),
    AccountContract.IAccountPresenter {

    override fun getUserLiveAccountList(token: String) {
        getView()?.showLoading()
        getModel().getUserLiveAccountList(
            token,
            object :
                IBaseCallBack<ResponseResult<LiveAccountInfo>> {
                override fun onResponse(response: ResponseResult<LiveAccountInfo>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.ILiveTradeListView) {
                            it.handleUserLiveAccountList(response)
                        }
                    }
                }
            })
    }

    override fun getUserDemoAccountList(token: String) {
        getView()?.showLoading()
        getModel().getUserDemoAccountList(
            token,
            object :
                IBaseCallBack<ResponseResult<DemoAccountInfo>> {
                override fun onResponse(response: ResponseResult<DemoAccountInfo>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.IDemoTradeListView) {
                            it.handleUserDemoAccountList(response)
                        }
                    }
                }
            })
    }

    override fun createDemoAccount(token: String, request: AddDemoAccountRequest) {
        getView()?.showLoading()
        getModel().createDemoAccount(
            token,
            request,
            object :
                IBaseCallBack<ResponseResult<Any?>> {
                override fun onResponse(response: ResponseResult<Any?>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.IAddDemoAccountView) {
                            it.handleAddDemoAccount(response)
                        }
                    }
                }
            })
    }

    override fun createLiveAccount(token: String, request: AddLiveAccountRequest) {
        getView()?.showLoading()
        getModel().createLiveAccount(
            token,
            request,
            object :
                IBaseCallBack<ResponseResult<Any?>> {
                override fun onResponse(response: ResponseResult<Any?>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.IAddLiveAccountView) {
                            it.handleAddLiveAccount(response)
                        }
                    }
                }
            })
    }

    override fun modifyLeverage(token: String, request: ModifyLeverRequest) {
        getView()?.showLoading()
        getModel().modifyLeverage(
            token,
            request,
            object :
                IBaseCallBack<ResponseResult<Any?>> {
                override fun onResponse(response: ResponseResult<Any?>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.IModifyLeverView) {
                            it.handleModifyLever(response)
                        }
                    }
                }
            })
    }

    override fun modifyDemoLeverage(token: String, request: ModifyDemoLeverRequest) {
        getView()?.showLoading()
        getModel().modifyDemoLeverage(
            token,
            request,
            object :
                IBaseCallBack<ResponseResult<Any?>> {
                override fun onResponse(response: ResponseResult<Any?>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.IModifyLeverView) {
                            it.handleModifyLever(response)
                        }
                    }
                }
            })
    }

    override fun queryLeverage(token: String, tradeNo: String) {
        getView()?.showLoading()
        getModel().queryLeverage(
            token,
            tradeNo,
            object :
                IBaseCallBack<ResponseResult<AccountLeverInfo>> {
                override fun onResponse(response: ResponseResult<AccountLeverInfo>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.ILeverInfoView) {
                            it.handleLeverInfo(response)
                        }
                    }
                }
            })
    }

    override fun queryAccountCount(token: String, userId: String) {
        getView()?.showLoading()
        getModel().queryAccountCount(
            token,
            userId,
            object : IBaseCallBack<ResponseResult<AccountCount>> {
                override fun onResponse(response: ResponseResult<AccountCount>) {
                    getView()?.hideLoading()
                    getView()?.let {
                        if (it is AccountContract.IAccountCountView) {
                            it.handleAccountCount(response)
                        }
                    }
                }
            })
    }
}